#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include "EquationSolver.h"

using namespace std;

class func: public Function
{
    public:
        double get_value(double x){
            if (cos(x) == 0){
                cout << "Error: 'tan(x)' does not exist!" <<endl;
                return 0;
            }else{
                return x-tan(x);
            }
        }
        /*double get_derivation(double x){
            if (cos(x) == 0){
                cout << "Error: divided by zero!" <<endl;
                return 0;
            }else{
                return 1.0-1.0/(cos(x)*cos(x));
            }
        }*/
}f;

int main()
{
    cout << "Newton's Method Test: "<<endl;
    double e = 1e-8;
    double m = 30;
    Newton new_solver(e, m);

    double x1 = 4.5, x2 = 7.7;
    InitInput input1(f), input2(f);
    input1.setNewtonInput(x1);
    double r1 = new_solver.solve(input1);
    cout << "the approximate root of f near 4.5: r1 = "<< r1 << endl;
    cout << "the value of the root: f(r1) = "<< f.get_value(r1) <<endl;
    cout << endl;

    input2.setNewtonInput(x2);
    double r2 = new_solver.solve(input2);
    cout << "the approximate root of f near 7.7: r2 = "<< r2 << endl;
    cout << "the value of the root: f(r2) = "<< f.get_value(r2) <<endl;

    return 0;
}